package com.Ajava1704.for设计模式.for动态代理.Jdk动态代理;

import java.lang.reflect.Proxy;

/**
 * 作者: LCG
 * 日期: 2020/2/14 08:47
 * 描述:
 */
public class ForTest001 {
    public static void main(String[] args) {
        //为接口创建代理类
       /* ForMyInvocationHandler forMyInvocationHandler=new ForMyInvocationHandler();

        Class<?>[] interfaces ={ForTestInterface.class};

        ForTestInterface testInterface =(ForTestInterface)Proxy.newProxyInstance(ForTestInterface.class.getClassLoader(), interfaces, forMyInvocationHandler);

        System.out.println(testInterface.test());*/


       //为接口的实现类创建代理对象
       ForTestInerfaceImpl forTestInerface=new ForTestInerfaceImpl();
       ForMyInvocationHandler2<ForTestInerfaceImpl> forMyInvocationHandler2=new ForMyInvocationHandler2<>(forTestInerface);

       //ForTestInterface forTestInterface = (ForTestInterface)Proxy.newProxyInstance(ForTestInerfaceImpl.class.getClassLoader(), ForTestInerfaceImpl.class.getInterfaces(), forMyInvocationHandler2);
        //System.out.println(forTestInterface.test());

        ForTestTTT<ForTestInterface> forTestInterfaceForTestTTT=new ForTestTTT<>();

        ForTestInterface proxyObject = forTestInterfaceForTestTTT.getProxyObject(ForTestInerfaceImpl.class.getClassLoader(), ForTestInerfaceImpl.class.getInterfaces(), forMyInvocationHandler2);

        System.out.println(proxyObject.test());

    }
}
